package crawler

import "strings"

func url2Name(url string) (filePath, fileName string) {
	if strings.HasPrefix(url, "https://") {
		url = strings.TrimPrefix(url, "https://")
	} else if strings.HasPrefix(url, "http://") {
		url = strings.TrimPrefix(url, "http://")
	}
	urlSp := strings.Split(url, "/")
	filePath = strings.Join(urlSp[:len(urlSp)-1], "/")
	fileName = urlSp[len(urlSp)-1]
	if fileName == "" {
		fileName = "index.html"
	} else if !strings.Contains(fileName, ".") {
		fileName = fileName + ".html"
	}
	return
}
